<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BannerController extends  AdminController{
    public function banner(){
        return view('banner.bannerlist');
    }

    public function bannerList(){
        $data = DB::table('banner_list')->get();
        foreach ($data as $k=>$v){
            $data[$k]->pic  =  $v->pic;
        }
        return response()->json(array('code'=>0,'msg'=>'','data'=>$data));
    }

    public function addBanner(Request $request){

        if($request->isMethod('post')){
          $data = $request->all();
          $imgAry = $data['pic'];
          $num = count($imgAry);
          for ($i = 0;$i < $num;$i++){
              $adddata[] = [
                  'otype' => $data['otype'],
                  'phone_type' => $data['phone_type'],
                  'pic' => $data['pic'][$i],
                  'title' => $data['title'][$i],
                  'url' => $data['url'][$i],
              ];
          }
            $res = DB::table('banner_list')->insert($adddata);
            if ($res){
                return response()->json(array('code'=>1,'msg'=>'新增成功'));
            }else{
                return response()->json(array('code'=>0,'msg'=>"新增失败"));
            }
        }

        return view('banner.addbanner');
    }

    public function editBanner(Request $request){
        $data = $request->all();
    }


}